{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# Numpy 练习题\n",
    "\n",
    "（1）导入 Numpy 库"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "e787a46a0c0cb7de"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "import numpy as np"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "aa69b575be2634b8"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（2）创建一个长度为 10 的空向量"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "2a2911fdc467d4d7"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "arr = np.zeros(10)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "c607dbede9d1140a"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（3）创建一个值域范围从 0 到 9 的向量"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "17fd53d8e47667b3"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "arr = np.arange(0, 10)"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "a70c2c0c51622694"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（4）反转一个向量"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "6d276cfaa430d7c1"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "arr = np.arange(5, 13)\n",
    "\n",
    "print(f'反转前：\\n{arr}')\n",
    "\n",
    "arr = arr[::-1]\n",
    "\n",
    "print(f'反转后：\\n{arr}')"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "44401505d77d975"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（5）创建一个 3 × 3 并且值从 0 到 9 的矩阵"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "f9d34221b42cfa6c"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "arr = np.arange(9).reshape(3, 3)\n",
    "\n",
    "arr"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "6327a0e7294604b9"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（6）找到数组 [1,0,4,5,0,1] 中非 0 元素的索引"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "3db42addf3a5fc43"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "nz_indexs = np.nonzero([1, 0, 4, 5, 0, 1])\n",
    "\n",
    "nz_indexs"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "a022fd005cb71299"
  },
  {
   "cell_type": "markdown",
   "source": [
    "（7）创建一个 3 × 3 × 3 的随机数组"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "78100a4993970422"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "arr = np.random.random((3, 3, 3))\n",
    "\n",
    "arr"
   ],
   "metadata": {
    "collapsed": false
   },
   "id": "21ec47e7e97cda0a"
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   },
   "id": "8cf11db760d1884c"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
